package com.acwing.partition44;

import java.io.*;
import java.util.Arrays;

/**
 * @author rkc
 * @date 2022/7/30 9:06
 */
public class AC4336唯一最小生成树 {

    private static final int N = 110, M = 2 * N, D = (int) (Math.log(N) / Math.log(2));
    private static Edge[] edges = new Edge[N * N];
    private static int[] parent = new int[N];
    private static boolean[] st = new boolean[N * N];

    private static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M], dep = new int[N];
    private static int[][] f = new int[N][D + 1], maxw = new int[N][D + 1];
    private static int[] q = new int[N];
    private static int n, m, idx;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int k = nextInt();
        while (k-- > 0) {
            n = nextInt(); m = nextInt();
            init();
            for (int i = 0; i < m; i++) edges[i] = new Edge(nextInt(), nextInt(), nextInt());
            //寻找MST，标记每一条边，并据此建图
            long mst1 = kruskal(), mst2 = (long) 1e18;
            bfs();
            for (int i = 0; i < m; i++) {
                if (!st[i]) {
                    int u = edges[i].u, v = edges[i].v, w = edges[i].w;
                    mst2 = Math.min(mst2, mst1 + w - lca(u, v));
                }
            }
            writer.println(mst2 > mst1 ? mst1 : "Not Unique!");
        }
        writer.flush();
    }

    private static int lca(int x, int y) {
        int max = -1;
        if (dep[x] < dep[y]) {
            int t = x;
            x = y;
            y = t;
        }
        for (int i = D; i >= 0; i--) {
            if (dep[f[x][i]] >= dep[y]) {
                max = Math.max(max, maxw[x][i]);
                x = f[x][i];
            }
        }
        if (x != y) {
            for (int i = D; i >= 0; i--) {
                if (f[x][i] != f[y][i]) {
                    max = Math.max(max, Math.max(maxw[x][i], maxw[y][i]));
                    x = f[x][i];
                    y = f[y][i];
                }
            }
            max = Math.max(max, Math.max(maxw[x][0], maxw[y][0]));
        }
        return max;
    }

    private static void bfs() {
        int qh = 0, qt = -1;
        q[++qt] = 1;
        dep[1] = 1;
        while (qh <= qt) {
            int u = q[qh++];
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                if (dep[v] != 0) continue;
                dep[v] = dep[u] + 1;
                f[v][0] = u;
                maxw[v][0] = w[i];
                for (int j = 1; j <= D; j++) {
                    int anc = f[v][j - 1];
                    f[v][j] = f[anc][j - 1];
                    maxw[v][j] = Math.max(maxw[v][j - 1], maxw[anc][j - 1]);
                }
                q[++qt] = v;
            }
        }
    }

    private static long kruskal() {
        long res = 0;
        Arrays.sort(edges, 0, m);
        for (int i = 0; i < m; i++) {
            int u = edges[i].u, v = edges[i].v, w = edges[i].w, fu = find(u), fv = find(v);
            if (fu != fv) {
                st[i] = true;
                parent[fu] = fv;
                res += w;
                add(u, v, w);
                add(v, u, w);
            }
        }
        return res;
    }

    private static void init() {
        idx = 0;
        Arrays.fill(st, false);
        for (int i = 0; i < N; i++) {
            parent[i] = i;
            h[i] = -1;
            dep[i] = 0;
        }
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }

    private static int find(int x) {
        if (parent[x] != x) parent[x] = find(parent[x]);
        return parent[x];
    }

    private static class Edge implements Comparable<Edge> {
        private int u, v, w;

        public Edge(int u, int v, int w) {
            this.u = u;
            this.v = v;
            this.w = w;
        }

        @Override
        public int compareTo(Edge o) {
            return Integer.compare(w, o.w);
        }
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
